<?php
require_once ("../src/db/connectdatabase.php");

function getApplyWeb($id) {
	$con = new ConnectDB();
	
	$tbl = "registry_apply_web";
	$fn = array('id', 'name', 'content', 'isread', 'dateregis');
	$condetion = array('id' => $id);
	return $con -> getvalue($tbl, $fn, $condetion);
}

function updateReadApplyWeb($id) {
	$con = new ConnectDB();
	
	$tbl = "registry_apply_web";
	$fn = array('isread' => 1);
	$conf = array('id' => $id);
	return $con -> update($tbl, $fn, $conf);
}

function int_to_date($int) {
    $time  = date("d-m-Y", $int);
    return $time;
}

if(isset($_GET['id'])) {
	$id = $_GET['id'];
	$arrData = getApplyWeb($id);
	if(count($arrData) == 1) {
		updateReadApplyWeb($id);
?>

<link rel="stylesheet" type="text/css" href="../css/jquery-ui.css">
<script src="../ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="../js/jquery-uicaledate.js"></script>
<h3>Cập Nhật Ưu Đãi <?php echo($arrData[0][1]) ?></h3>
<div style="color: red;">
<?php
	if(isset($_GET['mess'])) {
		echo($_GET['mess']);
	}
?>
</div>
<div>
	<table border="1px;" cellpadding="0" cellspacing="0">
    	<tr>
        	<th align="left" valign="top" width="150px;">Tên khách hàng</th>
            <td><?php echo($arrData[0][1]) ?></td>
        </tr>
        <tr>
        	<th align="left" valign="top">Nội dung</th>
            <td><br><?php echo($arrData[0][2]) ?></td>
        </tr>
        <tr>
        	<th align="left" valign="top">Ngày đăng ký</th>
            <td><?php echo(int_to_date($arrData[0][4])) ?></td>
        </tr>
        <tr>
        	<th align="left" valign="top">Xóa</th>
            <td><input type="button" value="Xóa" class="btn-delete" idedit="<?php echo($arrData[0][0]) ?>" /></td>
        </tr>
    </table>
</div>
<script>
$(document).on('click', '.btn-delete', function(e) {
	elem = $(this)
	var id = elem.attr("idedit");
	if(confirm("Bạn có muốn xóa?")) {
		$.ajax({
			url: "../src/ajax/ajaxApplyWeb.php",
			type: "post",
			data: {act:'del', idre: id},
			dataType:"json",
			success: function(data) {
				if(data == true) {
					window.location = "/admin/admin.php?content=apply-from-web";
				} else {
					alert("Cập nhật dữ liệu không thành công");
				}
			}
		});
	}
});
</script>
<?php
	}
}
?>